package org.j4me.info;

import javax.microedition.midlet.MIDlet;

import org.j4me.ui.Dialog;
import org.j4me.ui.components.RadioButton;
import org.j4me.ui.components.TextBox;

public class DeviceDescriptionScreen extends Dialog {
	
	
	private TextBox _model;
	private RadioButton _brand;
	private TextBox _operator;
	private MIDlet _app;

	public DeviceDescriptionScreen(MIDlet app) {
		_app = app;
		setTitle("J4ME - Device Info");
		
		_brand = new RadioButton();
		_brand.setLabel("Brand");
		String[] names = new String[] {
				"choose one ",
				"Alcatel", "HTC","QTEK","Orange","Lg", "Motorola", "Nec" , "Nokia", "Samsung", "Sanyo", "Sharp", "Siemens", "Sun", "BlackBerry", "Sony-Ericsson", "Other"		
				
		};
		for(int i= 0; i < names.length;i++)
			_brand.append(names[i]);
		append(_brand);
		
		
		_model = new TextBox();
		_model.setLabel("Model");
		
		append(_model);
		
		
		_operator = new TextBox();
		_operator.setLabel("Operator");
		
	
		
		append(_operator);
		
		setMenuText(null, "Next");
		
	}

	protected void acceptNotify() {
			
		if(_brand.getSelectedIndex() == 0)
		{
				MessageScreen scr = new MessageScreen(this,"Please, choose a brand name.");
				scr.show();
				this.setSelected(0);
		}
		else if(_model.getString() == null || _model.getString().trim().length() == 0)
		{
			MessageScreen scr = new MessageScreen(this,"Please, choose a model name.");
			scr.show();
			this.setSelected(1);
			
		}
		else {
		DeviceInfo info = new DeviceInfo(_app);
		info.setBrand(_brand.getSelectedValue());
		info.setModel(_model.getString());
		info.setOperator(_operator.getString());
		InfoScreen screen = new InfoScreen(_app, info);
		screen.show();
		screen.populate();
		}

	}
}
